package com.crawler.utils;


import java.util.HashMap;

/**
 * http请求返回参数
 *
 * <pre>
 *  "{"success":false,"data":"","message":"VERBOSE ERROR"}"
 * </pre>
 */
public class Response extends HashMap<String, Object> {

    private static final long serialVersionUID = -2791356338016228077L;

    public Response() {
        super();
    }

    public Response(final boolean success) {
        super();
        put("success", success);
    }

    public static Response success() {
        return new Response(true);
    }

    public static Response successRes4Find(final Object data, final Integer total) {
        final Response response = new Response(true);
        response.setData(data);
        response.put("total", total);
        return response;
    }

    public static Response successResWithData(final Object data) {
        final Response response = new Response(true);
        response.setData(data);
        return response;
    }

    public static Response errorRes(final String error) {
        final Response response = new Response(false);
        response.setErrorMsg(error);
        return response;
    }

    public void setData(final Object data) {
        put("data", data);
    }

    public Object getData() {
        return get("data");
    }

    public boolean isSuccess() {
        return (Boolean) get("success");
    }

    public void setSuccess(final boolean success) {
        put("success", success);
    }

    public void setErrorMsg(final String errorMsg) {
        put("error", errorMsg);
    }

    public String getErrorMsg() {
        return (String) get("error");
    }
}